<?php
error_reporting(0);
session_start();

include_once "src/controller/regmanagement/AdminManager.php";

if (isset($_POST["submitAdminLoginFormButton"])) {

    try {
        $isAdminLogin = AdminManager::isAdminLogInValid($_POST['adminLogin'], $_POST['adminPassword']);
    } catch (Exception $e) {
        $isAdminLogin = false;
    }

    if ($isAdminLogin) {
        $_SESSION["isAdminLogin"] = true;
    } else {
        $_SESSION["isAdminLogin"] = false;
    }

} else {
    $isAdminLogin = false;
}

?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <meta name="keywords" content="">
        <meta name="description" content="">
        <title>Safety & Security Consultant Registry of Texas</title>
        <style type="text/css">
            @import "js/dojo/dojox/image/resources/image.css";
            @import "js/dojo/dijit/themes/tundra/tundra.css";
        </style>
        <link href="styles/default.css"
              rel="stylesheet"
              type="text/css"
              media="all">
        <script src="js/dojo/dojo/dojo.js"
                type="text/javascript"
                djConfig="parseOnLoad:true">
        </script>
        <script src="js/default.js" type="text/javascript"></script>
        <script type="text/javascript">
            dojo.require("dojo.parser");
            dojo.require("dijit.form.Button");
            dojo.require("dijit.form.Form");
            dojo.require("dijit.Dialog");
            dojo.require("dijit.form.ValidationTextBox");
            dojo.require("dijit.form.Textarea");
            
            function highlightLeftMenu1 () {
                dojo.byId("leftMenu1").style.backgroundColor = "#3B92BC";
                dojo.byId("leftMenu2").style.backgroundColor = "#686C7A";
                dojo.byId("leftMenu3").style.backgroundColor = "#686C7A";
                dojo.byId("leftMenu4").style.backgroundColor = "#686C7A";
                dojo.byId("leftMenu5").style.backgroundColor = "#686C7A";
                dojo.byId("leftMenu6").style.backgroundColor = "#686C7A";
            }
            
            dojo.addOnLoad(function () {
                dojo.connect(dijit.byId('sendRegistryCountsReportDialog'), 'hide', function(){
                    document.body.style.overflow = "";
                    clearRegistryCountsReporForm();

                    highlightLeftMenu1();
                });

                dojo.connect(dijit.byId('sendMassCommunicationMessageDialog'), 'hide', function(){
                    document.body.style.overflow = "";
                    clearMassCommunicationMessageForm();

                    highlightLeftMenu1();
                });

                dojo.connect(dijit.byId('sendManageCategoriesDialog'), 'hide', function(){
                    dojo.byId("adminManageCategoriesDialogArea").style.display = "";
                    dojo.byId("adminUpdateCategoriesArea").style.display = "none";
                    document.body.style.overflow = "";
                    dojo.byId("categoryListArea").innerHTML = "<img style='margin-top:50px;' src='images/loaders/bigLoader.gif'>";
                    document.getElementById("manageCategoriesFormStatusMessage").setAttribute("class", "");
                    document.getElementById("manageCategoriesFormStatusMessage").setAttribute("className", "");
                    dojo.byId("manageCategoriesFormStatusMessage").innerHTML = "";
                    dijit.byId("categoryName").reset();

                    highlightLeftMenu1();
                });

                dojo.connect(dijit.byId('manageUserAccountDialog'), 'hide', function(){
                    document.body.style.overflow = "";
                    resetManageUserAccountForm();
                    highlightUserAccountAnimation();

                    highlightLeftMenu1();
                });

                dojo.connect(dijit.byId('sendManageCategoriesDialog'), 'show', function () {
                    dojo.byId("leftMenu2").style.backgroundColor = "#3B92BC";
                    dojo.byId("leftMenu1").style.backgroundColor = "#686C7A";
                });

                dojo.connect(dijit.byId('sendMassCommunicationMessageDialog'), 'show', function () {
                    dojo.byId("leftMenu3").style.backgroundColor = "#3B92BC";
                    dojo.byId("leftMenu1").style.backgroundColor = "#686C7A";
                });

                dojo.connect(dijit.byId('sendRegistryCountsReportDialog'), 'show', function () {
                    dojo.byId("leftMenu4").style.backgroundColor = "#3B92BC";
                    dojo.byId("leftMenu1").style.backgroundColor = "#686C7A";
                });

                dojo.connect(dijit.byId('manageUserAccountDialog'), 'show', function () {
                    //dojo.byId("leftMenu4").style.backgroundColor = "#3B92BC";
                    dojo.byId("leftMenu1").style.backgroundColor = "#686C7A";
                });

                logoutButtonImage_on = new Image ( );
                logoutButtonImage_off = new Image ( );

                logoutButtonImage_on.src = "images/buttons/logoutIn.png";
                logoutButtonImage_off.src = "images/buttons/logoutOut.png";

            });
        </script>
    </head>
    <body class="tundra">

        <?php include "adminSendRegistryCountsReportDialog.php"; ?>
        <?php include "adminSendMassCommunicationMessageDialog.php"; ?>
        <?php include "adminManageCategoriesDialog.php"; ?>
        <?php include "adminManageUserAccountDialog.php"; ?>

        <table class="main">
            <thead>
                <tr class="mainHeader">
                    <th align="center">
                        <table class="topMenuStructure" cellspacing="0" cellpadding="0" border="0">
                            <tbody>
                                <tr class="topMenuLogoRow">
                                    <td colspan="5" style="padding-top:0px;">
                                        <img src="images/Registry_topbar.png"
                                             alt="Registry_topbar"
                                             style="border:0px;"/></td>
                                </tr>
                                <tr class="topMenuButtonsRow">
                                    <td id="menu1"></td>
                                    <td id="menu2"></td>
                                    <td id="menu3"></td>
                                    <td id="menu4"></td>
                                    <td id="menu6"></td>
                                </tr>
                                <tr class="topMenuFooterRow">
                                    <td colspan="5"></td>
                                </tr>
                            </tbody>
                        </table>
                    </th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td align="center"
                        valign="top">
                        <table class="mainBody">
                            <tbody>
                                <tr style="height:15px;">
                                    <td style="width:175px;"></td>
                                    <td style="width:795px;"></td>
                                </tr>
                                <tr>
                                    <td valign="top">
                                        <div style="font-family:Verdana;font-size:12px;">
                                            <?php
                                                if ($isAdminLogin) {
                                            ?>
                                                    <div id="leftMenu">
                                                        <div id ="leftMenu1"
                                                             <?php
                                                             if ($isAccountHome) {
                                                             ?>
                                                                class="current"
                                                             <?php
                                                             } else {
                                                             ?>
                                                                class="current"
                                                             <?php
                                                             }
                                                             ?>
                                                        >
                                                            Recover User Account Info.
                                                        </div>
                                                        <div id ="leftMenu2"
                                                             <?php
                                                             if ($isProfilePage) {
                                                             ?>
                                                                class="current"
                                                             <?php
                                                             } else {
                                                             ?>
                                                                onclick="showManageCategories()"
                                                                onmouseover="activateLeftMenuButton('leftMenu2')"
                                                                onmouseout="deactivateLeftMenuButton('leftMenu2')"
                                                             <?php
                                                             }
                                                             ?>
                                                        >
                                                            Manage Categories
                                                        </div>
                                                        <div id ="leftMenu3"
                                                             <?php
                                                             if ($isAccountPage) {
                                                             ?>
                                                                class="current"
                                                             <?php
                                                             } else {
                                                             ?>
                                                                onclick="showSendMassCommunicationMessage()"
                                                                onmouseover="activateLeftMenuButton('leftMenu3')"
                                                                onmouseout="deactivateLeftMenuButton('leftMenu3')"
                                                             <?php
                                                             }
                                                             ?>
                                                        >
                                                            Send Mass Comm. Message
                                                        </div>
                                                    </div>
                                                    <div id="leftMenu">
                                                        <div id ="leftMenu4"
                                                             <?php
                                                             if ($isAccountHome) {
                                                             ?>
                                                                class="current"
                                                             <?php
                                                             } else {
                                                             ?>
                                                                onclick="showSendRegistryCountsReport()"
                                                                onmouseover="activateLeftMenuButton('leftMenu4')"
                                                                onmouseout="deactivateLeftMenuButton('leftMenu4')"
                                                             <?php
                                                             }
                                                             ?>
                                                        >
                                                            Send Registry Counts Report
                                                        </div>
                                                        <div id ="leftMenu5"
                                                             <?php
                                                             if ($isProfilePage) {
                                                             ?>
                                                                class="current"
                                                             <?php
                                                             } else {
                                                             ?>
                                                                onclick="goTo('ajaxAdminExportRegistryData.php');"
                                                                onmouseover="activateLeftMenuButton('leftMenu5')"
                                                                onmouseout="deactivateLeftMenuButton('leftMenu5')"
                                                             <?php
                                                             }
                                                             ?>
                                                        >
                                                            Export Users Summary (.csv)
                                                        </div>
                                                        <div id ="leftMenu6"
                                                             <?php
                                                             if ($isAccountPage) {
                                                             ?>
                                                                class="current"
                                                             <?php
                                                             } else {
                                                             ?>
                                                                onclick="goTo('ajaxAdminConsultantServicesData.php');"
                                                                onmouseover="activateLeftMenuButton('leftMenu6')"
                                                                onmouseout="deactivateLeftMenuButton('leftMenu6')"
                                                             <?php
                                                             }
                                                             ?>
                                                        >
                                                            Export User Services List (.csv)
                                                        </div>
                                                    </div>
                                                    <div style="padding:0px 10px 20px 0px;">
                                                        <a href="adminIndex.php">
                                                            <img src="images/buttons/logoutOut.png"
                                                                 id="logoutButtonImage"
                                                                 name="logoutButtonImage"
                                                                 onmouseover="button_on('logoutButtonImage');"
                                                                 onmouseout="button_off('logoutButtonImage');"
                                                                 style="border:0px;"
                                                                 alt="logoutIn"/>
                                                        </a>
                                                    </div>
                                            <?php
                                                } else {
                                            ?>
                                                    <div id="leftMenu">
                                                        <div id ="leftMenu7"
                                                             <?php
                                                             if ($isAccountHome) {
                                                             ?>
                                                                class="current"
                                                             <?php
                                                             } else {
                                                             ?>
                                                                onclick="goTo('index.php');"
                                                                onmouseover="activateLeftMenuButton('leftMenu7')"
                                                                onmouseout="deactivateLeftMenuButton('leftMenu7')"
                                                             <?php
                                                             }
                                                             ?>
                                                        >
                                                            Close Admin Panel
                                                        </div>
                                                    </div>
                                            <?php
                                                }
                                            ?>
                                            
                                        </div>
                                    </td>
                                    <td valign="top" style="padding-left:20px;">
                                        <table border="0" cellpadding="0" cellspacing="0" width="100%">
                                            <tbody>
                                                <tr>
                                                    <td class="pageMainTitle">
                                                        Admin Panel
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td style="padding-top:10px;">
                                                        <?php
                                                            if (!$isAdminLogin) {
                                                        ?>
                                                            <form  name="adminLoginForm"
                                                                   id="adminLoginForm"
                                                                   action="adminIndex.php"
                                                                   onsubmit="return validateAdminLoginFormArea();"
                                                                   method="post">
                                                                <div id="adminLoginFormArea">
                                                                    <div id="adminLoginFormStatusMessage"
                                                                         style="float:left;margin-bottom:5px;margin-right:550px;width:205px;padding-left:5px;"></div>
                                                                    <div style="font-family:Verdana;font-size:12px;font-weight:bold;margin-bottom:5px;">Login:</div>
                                                                    <div>
                                                                        <input style="width:200px;"
                                                                               type="text"
                                                                               name="adminLogin"
                                                                               id="adminLogin"
                                                                               value=""
                                                                               dojoType="dijit.form.ValidationTextBox"
                                                                               trim="true"
                                                                               regExp="[\a-zA-Z0-9\-\.\_\#]+[\@][a-zA-Z0-9\-\.\_\#]+[\.][a-zA-Z0-9\-\.\_\#]+"
                                                                               lowercase="true"
                                                                               required="true" />
                                                                    </div>
                                                                    <div style="margin-top:10px;font-family:Verdana;font-size:12px;font-weight:bold;margin-bottom:5px;">Password:</div>
                                                                    <div>
                                                                        <input style="width:200px;"
                                                                               type="password"
                                                                               name="adminPassword"
                                                                               id="adminPassword"
                                                                               value=""
                                                                               dojoType="dijit.form.ValidationTextBox"
                                                                               trim="true"
                                                                               regExp="[\a-zA-Z0-9\_]+"
                                                                               required="true" />
                                                                    </div>
                                                                    <div style="margin-top:10px;">
                                                                        <button dojoType=dijit.form.Button
                                                                                type="reset"
                                                                                name="resetAdminLoginFormButton"
                                                                                id="resetAdminLoginFormButton"
                                                                                iconClass="emptyIcon"
                                                                                onclick="resetAdminLoginForm()">
                                                                            Clear
                                                                        </button>
                                                                        <button dojoType="dijit.form.Button"
                                                                                type="submit"
                                                                                name="submitAdminLoginFormButton"
                                                                                id="submitAdminLoginFormButton"
                                                                                iconClass="emptyIcon">
                                                                            Login
                                                                        </button>
                                                                    </div>
                                                                </div>
                                                            </form>
                                                        <?php
                                                            } else {
                                                        ?>
                                                            <div id="adminOptionsArea"
                                                                 style="padding: 5px 5px 5px 5px;">
                                                                <form dojoType="dijit.form.Form"
                                                                      id="searchUserAccountsForm"
                                                                      name="searchUserAccountsForm"
                                                                      method="post"
                                                                      action="javascript:submitSearchUserAccountsForm();">
                                                                    <div>TBD</div>
                                                                    <div style="margin-top:10px;margin-bottom:10px;height:50px;">
                                                                        <div style="float:left;margin-right:10px;">
                                                                            <div style="font-weight:bold;padding:0px 0px 3px 0px;">
                                                                                First Name:
                                                                            </div>
                                                                            <div>
                                                                                <input style="width:190px;"
                                                                                       type="text"
                                                                                       name="firstName"
                                                                                       id="firstName"
                                                                                       value=""
                                                                                       dojoType="dijit.form.ValidationTextBox"
                                                                                       trim="true"
                                                                                       regExp="[\a-zA-Z\.\-\,\' ]+"
                                                                                       propercase="true" />
                                                                            </div>
                                                                        </div>
                                                                        <div style="float:left;margin-right:10px;">
                                                                            <div style="font-weight:bold;padding:0px 0px 3px 0px;">
                                                                                Last Name:
                                                                            </div>
                                                                            <div>
                                                                                <input style="width:200px;"
                                                                                       type="text"
                                                                                       name="lastName"
                                                                                       id="lastName"
                                                                                       value=""
                                                                                       dojoType="dijit.form.ValidationTextBox"
                                                                                       trim="true"
                                                                                       regExp="[\a-zA-Z\.\-\,\' ]+"
                                                                                       propercase="true" />
                                                                            </div>
                                                                        </div>
                                                                        <div style="float:left;margin-right:10px;">
                                                                            <div style="font-weight:bold;padding:0px 0px 3px 0px;">
                                                                                Email:
                                                                            </div>
                                                                            <div>
                                                                                <input style="width:190px;"
                                                                                       type="text"
                                                                                       name="email"
                                                                                       id="email"
                                                                                       value=""
                                                                                       dojoType="dijit.form.ValidationTextBox"
                                                                                       trim="true"
                                                                                       regExp="[\a-zA-Z0-9\-\.\_\#]+[\@][a-zA-Z0-9\-\.\_\#]+[\.][a-zA-Z0-9\-\.\_\#]+"
                                                                                       propercase="true" />
                                                                            </div>
                                                                        </div>
                                                                        <div style="float:left;margin-right:10px;padding-top:17px;">
                                                                            <div>
                                                                                <button dojoType="dijit.form.Button"
                                                                                        type="button"
                                                                                        name="submitSearchUserAccountsButton"
                                                                                        id="submitSearchUserAccountsButton"
                                                                                        iconClass="searchIcon"
                                                                                        onclick="submitSearchUserAccountsForm();">
                                                                                    Search
                                                                                </button>
                                                                            </div>
                                                                        </div>
                                                                    </div>
                                                                    <div style="margin-top:0px;padding:0px;border:1px solid #CCCCCC;">
                                                                        <div  style="font-weight:bold;padding:5px 0px 5px 0px;background-color:#AAAAAA;color:#FFFFFF;text-align:center;">
                                                                            Search Results
                                                                        </div>
                                                                        <div id="userAccountsSearchResultsArea"
                                                                             style="padding:0px;height:400px;overflow:scroll;text-align:center;font-family:Verdana;font-size:12px;font-weight:bold;">
                                                                            <div style="margin-top:25px;">Please specify your search criteria above.</div>
                                                                        </div>
                                                                    </div>
                                                                </form>
                                                            </div>
                                                        <?php
                                                            }
                                                        ?>
                                                    </td>
                                                </tr>
                                            </tbody>
                                        </table>
                                    </td>
                                </tr>
                            </tbody>
                        </table>
                    </td>
                </tr>
                <tr>
                    <td align="center" valign="top">
                        <?php include "includes/mainFooterInclude.php"; ?>
                    </td>
                </tr>
            </tbody>
        </table>
    </body>
</html>
